/**
 * Copyright 2019 [shujiang.yang], Inc. All rights reserved.
 * Email: 314938230@qq.com
 **/
define("pages/jbxxFwdj/jbxxFwdj_jbxx_enter", [
        "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
        "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
        "../../plugins/artTemplate/artTemplate",
        "../../common/tools",
        "../../common/componts",
        "../../common/kss",
        "../../pages/jbxxFwdj/jbxxFwdj_jbxx_form",
        "../../pages/jbxxFwdj/jbxxFwdj_form.html.js"
    ],
    function(require) {
        var componts = require("../../common/componts");
        var kss=require("../../common/kss");
        var jbxxFwdjDialog = require("../../pages/jbxxFwdj/jbxxFwdj_jbxx_form");
        var jbxxTableId="jbxxTableId";
        var id;

        var getQueryDataGrid  = function(){
            return $('#'+jbxxTableId);
        };

        var initTable=function(){
            componts.initTable(jbxxTableId,{
                height:'615px',
                // url:"/jls_process/getProcessTaskList",
                url:"/jls_process/getProcessTaskList",
                fit:true,
                columns :  [
                    {field: 'id',title: '序号',formatter: function(value){return '<input type="radio" name="selectRadio1" value="'+value+'"/>';}},
                    {field : 'xm',width : 100,title:'姓名',sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}},
                    {field : 'jsh',title : '拘室号',hidden:false,width : 200,sortable:'true',formatter:function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}},
                    {field : 'bm',title : '别名',width : 200,sortable:'true',formatter:function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}},
                    {field : 'xbString',title : '性别',width : 200,sortable:'true',formatter: function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}},
                    {field : 'rsrq',title : '入所日期',width : 200,sortable:'true',formatter:function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}},
                    {field : 'ayString',title : '案别',width : 200,sortable:'true',formatter:function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}},
                    {field : 'dqbadw',title : '当前办案单位',width : 200,sortable:'true',formatter:function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}},
                    {field : 'gyqx',title : '拘押期限',width : 200,sortable:'true',formatter:function(value){return value?'<span title="'+value+'">'+value+'</span>':'';}},
                    {field:'operate',title:'详细信息',align:'center',width : 100,
                        formatter:function(value, row, index){
                            var str = '<a href="#" data-target="#ckPhoto" value="'+index+'" name="opera" data-toggle="modal" class="easyui-linkbutton"><img src="../../img/xq.png"></a>';
                            return str;
                        }
                    }
                ] ,
                onLoadSuccess:function(data){
                    if(data.total>0){
                        getQueryDataGrid().datagrid("selectRow", 0);
                        $("input[name='selectRadio1']")[0].checked = true;
                    }

                    $("a[name='opera']").each(function(){
                        $(this).on('click',function(){
                            var index=$(this).attr('value');
                            var jbxx=data.rows[index];
                            kss.initJbxxxx(jbxx.gcbh,jbxx.rybh,jbxx.xm+"--详细信息");
                        });
                    });
                },
                //单击行选中取消事件
                onClickRow: function (rowIndex, rowData) {
                    if(id!=rowData.id){
                        $("input[name='selectRadio1']")[rowIndex].checked = true;
                        getQueryDataGrid().datagrid("selectRow", rowIndex);
                        id=rowData.id;
                    }else if(id==rowData.id){
                        getQueryDataGrid().datagrid("unselectRow",rowIndex);
                        $("input[name='selectRadio1']")[rowIndex].checked = false;
                        id="";
                    }
                    //加入列表中
                    kss.zjryClick(rowData);
                },
                queryParams : {
                    "processDefinitionKey":componts.getUrlParam('processDefinitionKey'),
                    "taskDefinitionKey":componts.getUrlParam('taskDefinitionKey'),
                    "pageSize" : function(){
                        return getQueryDataGrid().datagrid("getPager").pagination("options").pageSize;
                    },
                    "pageIndex" : function(){
                        return getQueryDataGrid().datagrid("getPager").pagination("options").pageNumber;
                    }
                }
            })
            //页面高度自适应
            getQueryDataGrid().datagrid('resize',{
                height:($(window).height()-140)
            });
        }
        /**
         * 数据列表刷新加载
         */
        var loadDataGrid = function(){
            var formData = $(".awd-query-form").serializeObject();
            var queryParams = $.extend({},formData,{"state":"R8",
                "processDefinitionKey":componts.getUrlParam('processDefinitionKey'),
                "taskDefinitionKey":componts.getUrlParam('taskDefinitionKey'),
                "pageSize" : function(){
                    return getQueryDataGrid().datagrid("getPager").pagination("options").pageSize;
                },
                "pageIndex" : function() {
                    return getQueryDataGrid().datagrid("getPager").pagination("options").pageNumber;
                }});
            getQueryDataGrid().datagrid('clearSelections');
            getQueryDataGrid().datagrid('load',queryParams);
        };


        //绑定事件
        var bindAction=function(){
            //查询事件
            $(".query-btn").on("click",function(){
                loadDataGrid();
            });

            $(".awd-add-btn").on('click',function(){
                var selectedPerson =getQueryDataGrid().datagrid('getSelected');
                if(selectedPerson){
                    var ryxx = selectedPerson;
                    jbxxFwdjDialog.show(ryxx,loadDataGrid);
                }else{
                    $.messager.alert("提示","请选择要办理的记录!","info");
                }
            });
        };

        var init = function(){
            initTable();
            bindAction();
            componts.initSelectPage(undefined);
            componts.initSelect(undefined,undefined,undefined);
        };
        init();
    });